from jili.calc import calcor_base
import numpy as np
class X3yan(calcor_base):
    def __init__(self,ta_arg={}):
        self.out = ["X3yan3yin"]
        self.input = ["open","close"]
        self.parameters = {"timeperiod":3}
        super().__init__(ta_arg)
        self.batch=self.parameters["timeperiod"]
        self.lookback = self.batch - 1
    def calc(self):
        rst=0
        o = self.hisbars[self.input[0]]
        c = self.hisbars[self.input[1]]
        t1=c>o
        if False not in t1:#yan
            t2 = np.diff(o)>0
            if False not in t2:
                t3 = np.diff(c)>0
                if False not in t3:
                    rst=2
        elif True not in t1:#yin
            t2 = np.diff(o) < 0
            if False not in t2:
                t3 = np.diff(c) < 0
                if False not in t3:
                    rst = -2
        return rst